package com.amap.demo.view;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.amap.api.maps.AMap;
import com.amap.api.maps.MapView;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 地图图层
 *
 * @author ys
 */
public class BasicMapActivity extends AppCompatActivity implements RadioGroup.OnCheckedChangeListener, CompoundButton.OnCheckedChangeListener {

    @Bind(R.id.basic_map)
    MapView mapView;
    @Bind(R.id.rbtn_normal)
    RadioButton rbtnNormal;
    @Bind(R.id.rbtn_satellite)
    RadioButton rbtnSatellite;
    @Bind(R.id.rbtn_night)
    RadioButton rbtnNight;
    @Bind(R.id.basic_rgroup)
    RadioGroup basicRgroup;
    @Bind(R.id.basic_chbox)
    CheckBox basicChbox;

    private AMap aMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_basic_map);
        ButterKnife.bind(this);

        mapView.onCreate(savedInstanceState);

        init();
    }

    /**
     *
     */
    private void init() {
        if (null == aMap) {
            aMap = mapView.getMap();
        }
        basicRgroup.setOnCheckedChangeListener(this);
        basicChbox.setOnCheckedChangeListener(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        mapView.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
        mapView.onPause();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mapView.onDestroy();
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        mapView.onSaveInstanceState(outState);
    }

    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        switch (checkedId) {
            case R.id.rbtn_normal:
                aMap.setMapType(AMap.MAP_TYPE_NORMAL);
                break;
            case R.id.rbtn_satellite:
                aMap.setMapType(AMap.MAP_TYPE_SATELLITE);
                break;
            case R.id.rbtn_night:
                aMap.setMapType(AMap.MAP_TYPE_NIGHT);
                break;
            default:

                break;
        }
    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        aMap.setTrafficEnabled(isChecked);
    }
}
